
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.CureMedicine;
import cn.edu.scau.cmi.hombio.domain.CureTaskMedicine;
import cn.edu.scau.cmi.hombio.domain.FodderType;
import cn.edu.scau.cmi.hombio.domain.PreventionType;
import cn.edu.scau.cmi.hombio.domain.Unit;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class UnitServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected UnitService service;

	/**
	 * Instantiates a new UnitServiceTest.
	 *
	 */
	public UnitServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Return all Unit entity
	* 
	 */
	@Test
	public void findAllUnits() {
		// TODO: JUnit - Populate test inputs for operation: findAllUnits 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Unit> response = null;
		response = service.findAllUnits(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllUnits
	}

	/**
	 * Operation Unit Test
	* Delete an existing PreventionType entity
	* 
	 */
	@Test
	public void deleteUnitPreventionTypesForReportUnitId() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnitPreventionTypesForReportUnitId 
		Integer unit_id = 0;
		Integer related_preventiontypesforreportunitid_id = 0;
		Unit response = null;
		response = service.deleteUnitPreventionTypesForReportUnitId(unit_id, related_preventiontypesforreportunitid_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUnitPreventionTypesForReportUnitId
	}

	/**
	 * Operation Unit Test
	* Delete an existing PreventionType entity
	* 
	 */
	@Test
	public void deleteUnitPreventionTypesForUnitId() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnitPreventionTypesForUnitId 
		Integer unit_id_1 = 0;
		Integer related_preventiontypesforunitid_id = 0;
		Unit response = null;
		response = service.deleteUnitPreventionTypesForUnitId(unit_id_1, related_preventiontypesforunitid_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUnitPreventionTypesForUnitId
	}

	/**
	 * Operation Unit Test
	* Load an existing Unit entity
	* 
	 */
	@Test
	public void loadUnits() {
		Set<Unit> response = null;
		response = service.loadUnits();
		// TODO: JUnit - Add assertions to test outputs of operation: loadUnits
	}

	/**
	 * Operation Unit Test
	* Delete an existing FodderType entity
	* 
	 */
	@Test
	public void deleteUnitFodderTypes() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnitFodderTypes 
		Integer unit_id_2 = 0;
		Integer related_foddertypes_id = 0;
		Unit response = null;
		response = service.deleteUnitFodderTypes(unit_id_2, related_foddertypes_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUnitFodderTypes
	}

	/**
	 * Operation Unit Test
	* Save an existing Unit entity
	* 
	 */
	@Test
	public void saveUnit() {
		// TODO: JUnit - Populate test inputs for operation: saveUnit 
		Unit unit = new cn.edu.scau.cmi.hombio.domain.Unit();
		service.saveUnit(unit);
	}

	/**
	 * Operation Unit Test
	* Save an existing CureTaskMedicine entity
	* 
	 */
	@Test
	public void saveUnitCureTaskMedicines() {
		// TODO: JUnit - Populate test inputs for operation: saveUnitCureTaskMedicines 
		Integer id = 0;
		CureTaskMedicine related_curetaskmedicines = new cn.edu.scau.cmi.hombio.domain.CureTaskMedicine();
		Unit response = null;
		response = service.saveUnitCureTaskMedicines(id, related_curetaskmedicines);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUnitCureTaskMedicines
	}

	/**
	 * Operation Unit Test
	* Delete an existing CureTaskMedicine entity
	* 
	 */
	@Test
	public void deleteUnitCureTaskMedicines() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnitCureTaskMedicines 
		Integer unit_id_3 = 0;
		Integer related_curetaskmedicines_id = 0;
		Unit response = null;
		response = service.deleteUnitCureTaskMedicines(unit_id_3, related_curetaskmedicines_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUnitCureTaskMedicines
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findUnitByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findUnitByPrimaryKey 
		Integer id_1 = 0;
		Unit response = null;
		response = service.findUnitByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findUnitByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Save an existing CureMedicine entity
	* 
	 */
	@Test
	public void saveUnitCureMedicines() {
		// TODO: JUnit - Populate test inputs for operation: saveUnitCureMedicines 
		Integer id_2 = 0;
		CureMedicine related_curemedicines = new cn.edu.scau.cmi.hombio.domain.CureMedicine();
		Unit response = null;
		response = service.saveUnitCureMedicines(id_2, related_curemedicines);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUnitCureMedicines
	}

	/**
	 * Operation Unit Test
	* Save an existing FodderType entity
	* 
	 */
	@Test
	public void saveUnitFodderTypes() {
		// TODO: JUnit - Populate test inputs for operation: saveUnitFodderTypes 
		Integer id_3 = 0;
		FodderType related_foddertypes = new cn.edu.scau.cmi.hombio.domain.FodderType();
		Unit response = null;
		response = service.saveUnitFodderTypes(id_3, related_foddertypes);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUnitFodderTypes
	}

	/**
	 * Operation Unit Test
	* Save an existing PreventionType entity
	* 
	 */
	@Test
	public void saveUnitPreventionTypesForUnitId() {
		// TODO: JUnit - Populate test inputs for operation: saveUnitPreventionTypesForUnitId 
		Integer id_4 = 0;
		PreventionType related_preventiontypesforunitid = new cn.edu.scau.cmi.hombio.domain.PreventionType();
		Unit response = null;
		response = service.saveUnitPreventionTypesForUnitId(id_4, related_preventiontypesforunitid);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUnitPreventionTypesForUnitId
	}

	/**
	 * Operation Unit Test
	* Delete an existing CureMedicine entity
	* 
	 */
	@Test
	public void deleteUnitCureMedicines() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnitCureMedicines 
		Integer unit_id_4 = 0;
		Integer related_curemedicines_id = 0;
		Unit response = null;
		response = service.deleteUnitCureMedicines(unit_id_4, related_curemedicines_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUnitCureMedicines
	}

	/**
	 * Operation Unit Test
	* Delete an existing Unit entity
	* 
	 */
	@Test
	public void deleteUnit() {
		// TODO: JUnit - Populate test inputs for operation: deleteUnit 
		Unit unit_1 = new cn.edu.scau.cmi.hombio.domain.Unit();
		service.deleteUnit(unit_1);
	}

	/**
	 * Operation Unit Test
	* Return a count of all Unit entity
	* 
	 */
	@Test
	public void countUnits() {
		Integer response = null;
		response = service.countUnits();
		// TODO: JUnit - Add assertions to test outputs of operation: countUnits
	}

	/**
	 * Operation Unit Test
	* Save an existing PreventionType entity
	* 
	 */
	@Test
	public void saveUnitPreventionTypesForReportUnitId() {
		// TODO: JUnit - Populate test inputs for operation: saveUnitPreventionTypesForReportUnitId 
		Integer id_5 = 0;
		PreventionType related_preventiontypesforreportunitid = new cn.edu.scau.cmi.hombio.domain.PreventionType();
		Unit response = null;
		response = service.saveUnitPreventionTypesForReportUnitId(id_5, related_preventiontypesforreportunitid);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUnitPreventionTypesForReportUnitId
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
